<?php 
// +----------------------------------------------------------------------
// | RXThinkCMF敏捷开发框架 [ 赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | 版权所有 2018~2023 南京RXThinkCMF研发中心
// +----------------------------------------------------------------------
// | Licensed LGPL-3.0 RXThinkCMF并不是自由软件，未经许可禁止去掉相关版权
// +----------------------------------------------------------------------
// | 官方网站: https://www.rxthink.cn
// +----------------------------------------------------------------------
// | Author: @牧羊人 团队荣誉出品
// +----------------------------------------------------------------------
// | 版权和免责声明:
// | 本团队对该软件框架产品拥有知识产权（包括但不限于商标权、专利权、著作权、商业秘密等）
// | 均受到相关法律法规的保护，任何个人、组织和单位不得在未经本团队书面授权的情况下对所授权
// | 软件框架产品本身申请相关的知识产权，禁止用于任何违法、侵害他人合法权益等恶意的行为，禁
// | 止用于任何违反我国法律法规的一切项目研发，任何个人、组织和单位用于项目研发而产生的任何
// | 意外、疏忽、合约毁坏、诽谤、版权或知识产权侵犯及其造成的损失 (包括但不限于直接、间接、
// | 附带或衍生的损失等)，本团队不承担任何法律责任，本软件框架禁止任何单位和个人、组织用于
// | 任何违法、侵害他人合法利益等恶意的行为，如有发现违规、违法的犯罪行为，本团队将无条件配
// | 合公安机关调查取证同时保留一切以法律手段起诉的权利，本软件框架只能用于公司和个人内部的
// | 法律所允许的合法合规的软件产品研发，详细声明内容请阅读《框架免责声明》附件；
// +----------------------------------------------------------------------

namespace app\admin\controller;


use app\admin\service\ExampleService;
use think\Db;

/**
 * 演示案例一管理-控制器
 * @author 牧羊人
 * @since: 2021/12/21
 * Class Example
 * @package app\admin\controller
 */
class Example extends Backend
{
    /**
     * 初始化方法
     * @author 牧羊人
     * @since: 2021/12/21
     */
    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->service = new ExampleService();
    }

    public function testaa()
    {
        echo ;die();
        $data = input();
        $data =  Db::table('think_student')->where('imei','863996207151601')
            ->find();
        if($data){
            $data['open_time'] = json_decode($data['open_time'],true);
            $data['time_range'] = json_decode($data['time_range'],true);
        }
        $res = [
            "msg" => '操作成功',
            "code" => 0,
            "count" => '',
            "data" => $data,
        ];
        return $this->jsonReturn($res);
    }

    public function test1()
    {
        //echo '111';die();
        //8639 9620715163 5
        //devive_id 取的是imei的5-14位吗？
        $imei = '863996207151635';
        $imei = substr($imei,4,10);

        $option = [
            "deviceId" => $imei,
            //"deviceId" => "6207151635",
        ];
        $url = 'https://api.gdjx-ai.com/ext/sendCommand/getPhoneBookWhitelist';
        $auth = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJqd3RfeWgiLCJleHAiOjE3Mjc1MTE5OTksInN1YiI6IllIIiwiYXVkIjoiZXZlcnkiLCJuYmYiOjE3MjY5MDcxOTksImlhdCI6MTcyNjkwNzE5OSwianRpIjoxMDAwMSwidWlkIjoxfQ.Eejun36uD4i1f_fm2ESNjd46q1Itg-fGrYYMcBNj26U';
        $headers = [
            'Content-Type' => 'application/json',
            'Authorization' => $auth,
        ];
        $client = new \GuzzleHttp\Client();
        $res = $client->request('POST', $url, [
            'json' => $option,
            'headers' => $headers
        ]);
        $req = $res->getBody()->getContents();
        $resdata = json_decode($req, true);
        print_r($resdata);
    }

    public function test2()
    {
        //echo '111';die();
        //8639 9620715163 5
        //devive_id 取的是imei的5-14位吗？
        $imei = '863996207151635';
        $imei = substr($imei,4,10);

        $option = [
            "deviceId" => $imei,
            'contactPersonList' => [
                "phone" => "", "name" => "",
            ],
        ];
        $url = 'https://api.gdjx-ai.com/ext/sendCommand/setPhoneBookWhitelist';
        $auth = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJqd3RfeWgiLCJleHAiOjE3Mjc1MTE5OTksInN1YiI6IllIIiwiYXVkIjoiZXZlcnkiLCJuYmYiOjE3MjY5MDcxOTksImlhdCI6MTcyNjkwNzE5OSwianRpIjoxMDAwMSwidWlkIjoxfQ.Eejun36uD4i1f_fm2ESNjd46q1Itg-fGrYYMcBNj26U';
        $headers = [
            'Content-Type' => 'application/json',
            'Authorization' => $auth,
        ];
        $client = new \GuzzleHttp\Client();
        $res = $client->request('POST', $url, [
            'json' => $option,
            'headers' => $headers
        ]);
        $req = $res->getBody()->getContents();
        $resdata = json_decode($req, true);
        print_r($resdata);
    }


    public function test()
    {
        //echo '111';die();
        //8639 9620715163 5
        //devive_id 取的是imei的5-14位吗？
        $imei = '863996207151635';
        $imei = substr($imei,4,10);

        $option = [
            "deviceId" => $imei,
            //"deviceId" => "6207151635",
        ];
        $url = 'https://api.gdjx-ai.com/ext/sendCommand/getDeviceInfo';
        $auth = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJqd3RfeWgiLCJleHAiOjE3Mjc1MTE5OTksInN1YiI6IllIIiwiYXVkIjoiZXZlcnkiLCJuYmYiOjE3MjY5MDcxOTksImlhdCI6MTcyNjkwNzE5OSwianRpIjoxMDAwMSwidWlkIjoxfQ.Eejun36uD4i1f_fm2ESNjd46q1Itg-fGrYYMcBNj26U';
        $headers = [
            'Content-Type' => 'application/json',
            'Authorization' => $auth,
        ];
        $client = new \GuzzleHttp\Client();
        $res = $client->request('POST', $url, [
            'json' => $option,
            'headers' => $headers
        ]);
        $req = $res->getBody()->getContents();
        $resdata = json_decode($req, true);
        print_r($resdata);
        if($resdata && isset($resdata['battery'])){
            $battery = $resdata['battery']; //电量
            $online = $resdata['online']; // 在线状态
            $stepCount = $resdata['stepCount']; //步数
        }
    }

                            	        
	/**
	 * 设置是否VIP	 
	 * @return mixed
	 * @since 2021/12/21	 
	 * @author 牧羊人	 
	 */
	public function setIsVip()
	{
		if (IS_POST) {
			$result = $this->service->setIsVip();
            return $this->jsonReturn($result);
		}
	}
    	                            
}